Skip to content

fix(files): cancel resumed runs across replicas, unify anchored file edits, and harden workspace, integration, and presence paths - #9035

Merged
waleedlatif1 merged 57 commits into
stagingfrom
fix/resume-stop-and-cross-area-fixes
Oct 14, 2026
Merged

waleedlatif1 merged 57 commits into
stagingfrom
fix/resume-stop-and-cross-area-fixes

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Execution

  • Stop during an active resume did not reach the running attempt when the Stop landed on another replica: the engine listened for cancellation on the durable run id while Stop signalled the attempt id. The resume attempt now subscribes to cancellation on its own id for its lifetime; a subscription failure is treated like an unavailable run buffer, so the pause stays retryable.
  • Evaluation models were accepted as Agent fallbacks at authoring time, and a saved one failed every run with a retryable error. The validator now rejects them, and the runtime refusal is non-retryable.
  • The Agent fallback loop now skips a cross-provider candidate that needs its own family credentials, through the same helper Router and Evaluator use.
  • Removed the Agent block's fallback normalization from its params mapping, which the Agent handler never runs.
  • Uncached deployment comparison materialization no longer deep-clones freshly read state.

Files

  • Anchored delete_between/replace_between failed when the end anchor also appeared before the start. occurrence selects the start anchor; the end anchor is the first match after it, and the v2 contract, File block, and tool descriptions now say so. An end anchor found only before the start now returns not_found (404) instead of a validation error (400). Copilot's edit tool and its streaming preview use the shared implementation instead of two inline copies. Behavior changes for those two callers: a trailing newline in inserted content no longer adds a blank line, and whitespace-only anchors are refused like the File block already refuses them.
  • Anchored edits preserve each line's own line ending instead of rewriting a mixed file to one ending, and build their line arrays without spreading inserted lines into one call, so very large inserts no longer overflow the call stack.
  • Resolving one named file inside a folder scope listed up to 5000 files and failed for larger folders; it now uses an exact-name scoped query with the same ambiguity and not-found errors.
  • Root plus subfolders is treated as unscoped instead of binding every folder id; the two duplicate folder-scope predicates are one helper.
  • The context-processing failure log records the context kind instead of the whole context (which can hold selected file text).
  • The untitled-file rename from the leading heading fires when the cursor leaves the heading, on an in-page blur, or on unmount, instead of after an idle pause, and only after a local edit that changed the document, so opening and leaving a file never renames it. The handler receives the file id explicitly.
  • useResourceFolders memoizes on stable query fields.

Projects and workspaces

  • Fork creation takes the Project lock shared; every holder it must exclude (archive, split, transfer, departure) takes it exclusively.
  • Banning a user archives every owned workspace and reports failures together instead of stopping at the first.
  • Removed dead guards on the non-null workspace.project_id; operator errors name release v0.9.18 instead of a PR number; the membership migration logs each repaired workspace's workflow ids after the repair commits.
  • Added indexes on chat.user_id and the legacy workspace_file.uploaded_by (migration 0429, concurrent) for member-removal ownership lookups.
  • Creator handoff loads file version heads in one query.
  • Admin cross-org workspace move preflight now reports source-org custom blocks used by the moving workspace but bound elsewhere, which stop resolving after the move. Replays report the recorded impact; the move flow drops dead code and contradictory comments.
  • RevokeWorkspaceAccessResult drops an unreachable variant; unresolvedWorkflows is renamed unresolvedWorkspaceIds.
  • Fork sync's per-param visibility map is one shared helper.

Integrations

  • Zoho Desk permanent webhook registration failures were retried until max attempts; they now fail terminally via WebhookDeploymentConfigurationError, classified in one helper in deploy.ts.
  • Zoho Desk, SailPoint, and Outlook calendar ids in URL paths go through safeUrlPathSegment, so ./.. can't redirect a request to another endpoint.
  • Outlook list-events page tokens must continue a calendarView, not just any Graph URL.
  • SailPoint token cache uses LRUCache with per-entry TTLs, keeping the cap of 100 concurrent token exchanges (an evicted exchange still counts until it settles); limits come from the schema constants.
  • Zoho Desk host helpers are shared; JWKS cache uses LRUCache. Ashby shares one error extractor. Profile-validation logs record keys only.

Realtime

  • File-editor presence no longer retries a fetch that timed out, keeps a roster change that arrived during a failed read (with a fresh retry allowance), and emits each snapshot before re-checking. Presence clearing is one helper and the relay registers once at startup.

Tables, logs, knowledge

  • workflow_input appears under Built-in Tools in the agent tool picker (picker split by base type).
  • Table query guidance states boolean columns reject range operators and builds operator lists from FILTER_OPS.
  • Logs keep archived workflows' names but do not open them; only a hard-deleted workflow reads as deleted.
  • Disabled-image removal keeps walking past a page that removed nothing; docs state the image cap is per sync run and each member-accounts continuation run can read up to it.

File accounting and retention

  • Bulk file-folder archive, restore, and delete-by-path take the Project lock, the workspace row, then the directory lock, the order uploads and registrations use; the two orders could deadlock in one workspace.
  • Workspace accounting locks only the workspace row while preparing and the payer row only when a non-zero delta is applied, so zero-delta and collab-state saves do not serialize on the organization row or fail without a payer stats row. Content commits drop a repeated Project lock; a folder-id upload target is a point query; the file list keeps one file-id filter.
  • Without cleanup budgets, one failing workspace file-folder cleanup or Project retention pass is logged and the rest of the run (knowledge bases, resource targets, orphan bindings, chat cleanup) continues. Folder cleanup locks only workspaces with an expired file folder; Project version and folder retention no longer lock the payer; the free-plan version cap is one constant.
  • An inline live-doc reconcile exception logs at warn again (the outbox retries it).
  • Outlook event and calendar ids containing / are encoded (%2F) instead of rejected; empty and dot-segment ids are still refused.

Type of Change

  • Bug fix

Testing

  • Regression tests that fail on the pre-fix code: resume Stop from another replica, evaluation-model fallback validation and non-retryable refusal, Agent cross-family skip, anchored end-after-start and mixed line endings, scoped name resolution past a large folder, root-with-subfolders scope, untitled rename on heading exit, Zoho config failure classification, Outlook page-token collection and path ids, SailPoint failed-exchange, 401 refresh, and concurrent-exchange cap, presence roster change during a failed read and non-retried adapter timeout, large anchored inserts, emptied replace_between line ending, resume cancellation-subscription failure, untitled file opened without edits, disabled-image removal past an empty page, archived workflow in logs (not openable, keeps its name).
  • New integration checks: upload and registration commit alongside a bulk archive queued first on the directory lock; an unbudgeted file-folder failure rolls back while the rest of the purge runs.
  • New integration suites: two-replica file-editor presence over the Redis adapter, admin cross-org workspace move, shared Project lock for file writers and fork creation.
  • Targeted unit suites for every changed area; check:migrations, offline drizzle-kit generate, artifact regeneration (tool metadata, docs manifest, agent stream docs, integration docs). Full lint, audits, type-check, and integration suites run in CI.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 14, 2026 8:37pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 163 files

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/workspaces/admin-move-source-impact.ts
Comment thread apps/sim/tools/outlook/calendar_list_events.ts Outdated
Comment thread apps/sim/lib/internal/sailpoint/client.ts
Comment thread apps/sim/lib/workspace-files/search/delivery.ts
Comment thread apps/sim/tools/sharepoint/utils.ts
Comment thread apps/sim/lib/workspace-files/edit-content.ts Outdated
@greptile-apps

greptile-apps Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no new blocking issue was found.

Summary

This PR fixes resumed-run cancellation across replicas, shares anchored file edits, and hardens file storage, workspace moves, integrations, and presence updates.

  • Stopping a resumed run reaches its active attempt.
  • Agent fallbacks reject evaluation models and skip candidates without matching credentials.
  • Anchored file edits choose the end anchor after the selected start and preserve line endings.
  • Folder-scoped file lookup uses an exact name query and treats root with subfolders as unscoped.
  • Untitled markdown files take their name from the finished leading heading.
  • File-editor presence rosters include collaborators connected to other replicas.
  • Fork creation shares the Project lock used by file writers, while lifecycle changes keep exclusive locks.
  • Workspace move preflight shows custom blocks that will stop resolving after a move.
  • File storage work takes locks in a shared order and applies payer updates only for real storage changes.
  • Unbudgeted retention runs continue other cleanup after one workspace or Project cleanup fails.
  • Permanent Zoho Desk webhook setup failures stop retrying as configuration errors.
  • Integration requests encode path IDs safely and keep Outlook paging within calendar views.
  • SailPoint token exchanges use bounded per-entry caching, and integration logs expose less sensitive detail.
  • Archived workflows keep their names in logs but are not openable.
  • Agent tool pickers list workflow_input, and table guidance reflects supported filter operators.
  • Workflow reference and fork paths share visibility helpers and avoid extra deployment-state copies.
  • Small supporting updates keep comments, tests, and generated check baselines in sync.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Start Project retention with shared limit] --> B[Delete one batch in a transaction]
  B --> C{Did the batch commit?}
  C -->|Yes| D[Subtract deleted rows from the limit]
  D --> E{Is any limit left?}
  E -->|Yes| B
  E -->|No| F[Return committed deletion count]
  C -->|No| G[Log the owner failure in an unbudgeted run]
  G --> H[Continue with the next Project using the remaining limit]
  H --> B
Loading

Reviews (7) · Last reviewed commit: "fix(retention): charge committed Project..." · Reviewed by Greptile

Comment thread apps/sim/lib/workspace-files/edit-content.ts Outdated
Comment thread apps/sim/lib/internal/sailpoint/client.ts Outdated
Comment thread apps/docs/content/docs/integrations/ashby.mdx Outdated
@waleedlatif1 waleedlatif1 changed the title fix: cancel resumed runs across replicas, unify anchored file edits, and harden workspace, integration, and presence paths fix(files): cancel resumed runs across replicas, unify anchored file edits, and harden workspace, integration, and presence paths Oct 14, 2026
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found and verified against the latest diff

Confidence score: 4/5

  • In file-doc-presence.integration.ts, await Server.close() can continue before the replica has finished closing, so shutting down the store and Redis clients may race with server teardown. Await the close callback first.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/realtime/src/handlers/file-doc-presence.integration.ts">

<violation number="1" location="apps/realtime/src/handlers/file-doc-presence.integration.ts:182">
P2: `Server.close()` completes through its callback, not a returned promise, so this `await` continues before the replica has finished closing. Await the callback before shutting down its store and Redis clients.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/realtime/src/handlers/file-doc-presence.integration.ts
Comment thread apps/sim/app/workspace/[workspaceId]/logs/utils.test.ts
@waleedlatif1
waleedlatif1 force-pushed the fix/resume-stop-and-cross-area-fixes branch from 848e59f to 05418f9 Compare October 14, 2026 19:28
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 147 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/tools/outlook/calendar-utils.ts Outdated
…very banned-user workspace, and drop dead membership guards

- requireForkProject takes the Project lock shared, so sibling file writers and
  other forks no longer wait out a fork's content copy; exclusive lifecycle
  holders (archive, split, transfer, departure) are still fenced
- disableUserResources keeps archiving after one workspace fails, logs the
  failed ids, and throws an AggregateError at the end
- remove null guards on workspace.project_id, which is NOT NULL
- name release v0.9.18 instead of a PR number in Project backfill operator errors
- log workspace and workflow ids per archive repair in the 0032 script migration

(cherry picked from commit 5831241070f08536eb923a4de012b0a58bdb5ff3)
…, share one anchored edit

The end anchor is now the first match after the selected start anchor, so a
closing line earlier in the file no longer fails the edit. Copilot's
apply_file_edit and its streaming preview route anchored patches through
applyWorkspaceFileContentEdit instead of two divergent copies. Anchored edits
keep each untouched line's own ending; inserted lines take the anchor's.

(cherry picked from commit fb3f81a1b7810c1dc8763f31b5a1479769f60803)
…t by listing the folder

resolveScopedFileReference listed up to 5000 files to find one name, so a named
write, append, or edit inside a larger folder failed payload_too_large. The id
and name lookups are now exact SQL predicates under the same folder scope and
list authorization, with the same not-found and ambiguity errors.

(cherry picked from commit 63a06782eb3327a6d858bc337600d88d76ce46c8)
… listing every folder id

A root scope including subfolders expanded to every active folder id, so file
listing and content search sent an IN list of up to every folder in the
workspace. It now resolves to no folder scope, which selects the same files:
archiving a folder archives the files in it. The two identical folder-scope
predicate builders become one workspaceFileFolderScopeCondition.

(cherry picked from commit 8020c141e6462cb2c97dfe2c992225ed3baad3ab)
…ms, log context kind only

Folder scope narrows a search; authorization is workspace-level, so the
comments no longer call it an isolation boundary. A failed chat context now
logs its kind rather than the whole context, which for a file selection carries
the user's selected text. The overlap-dedupe docstring keeps its invariants.

(cherry picked from commit 4c22ff11d982a0f57156746f6d07bce584b1d587)
…e, probe the id alongside folder resolution

(cherry picked from commit 0df6468f6372168cfbe9f3668eae213cee091b6c)
…ders, rename untitled files on heading exit

- file-upload: drop the effect that pruned out-of-scope selections from every open editor; flag them for removal instead
- use-resource-folders: memoize on stable query fields; fix byPath doc
- rich-markdown-editor: name an untitled file after its heading when the cursor leaves it, on blur, or on unmount (once), not after an idle pause; caller resolves the file by id
- table-grid: hoist guarded context row instead of non-null assertions
- drop a formula-restating test and trim a home.tsx comment

(cherry picked from commit 419520a1e42c3462b31ccbf2e68f7f8d6af4ae9d)
…another replica

The resumed engine subscribes to cancellation under the durable run id, while Stop records it under the attempt id. Subscribe the attempt's abort to its own id, and assert the durable snapshot id through executeWorkflowCore instead of a log message.

(cherry picked from commit facbad586a01aaeb624150af896dceb1a6430c47)
…nd fail saved ones without retry

(cherry picked from commit 80d07588a0c2b6b5edbd130497471f8f6594b801)
…credentials, as Router and Evaluator do

(cherry picked from commit 55eb1c8ba930d006bc130fa2de584dfa0f23291a)
@waleedlatif1
waleedlatif1 force-pushed the fix/resume-stop-and-cross-area-fixes branch from 3b34fd8 to 71b2734 Compare October 14, 2026 19:58
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 165 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/file-retention/failure.ts
…ith separators allowed

Outlook event and calendar ids share the guarded path-segment helper
(type guards, lone-surrogate check, dot-segment rejection) instead of a
local copy, opting in to percent-encoding / and \. The storage lock-order
note says the Project lock step applies to workspace writers only.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 166 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/tools/outlook/calendar-utils.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 166 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

…d run budget

Project version cleanup commits one transaction per batch. An unbudgeted run
isolates a failing owner, which reported zero rows even when batches before
the failure had committed, so later owners received the full remaining limit
again. Cleanup now charges each committed batch to one RowBudget shared across
the run, matching how archive cleanup decrements its budgets in place.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 166 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit bbfbf4e into staging Oct 14, 2026
42 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/resume-stop-and-cross-area-fixes branch October 14, 2026 20:46

This branch was previously deployed

1 inactive deployment
Preview — f7865435 Deployed Oct 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant